import { ref, reactive, watch, computed } from 'vue'

// 状态
let isLoaded = ref(false);
let loadingStateText = ref("加载中");
let landingPage = "";
let data = reactive({});
let baseUrl = "https://www.lin-home.com"
// 行为
function Enter() {
	if (!isLoaded.value) {
		return;
	}
	
	uni.redirectTo({
		url: landingPage
	})
}

export async function useServerData(landing) {
	if (landing) {
		landingPage = landing;
	}
	
	let msg = await uni.post("/api/pageSource/ppCms");
	isLoaded.value = true;
	loadingStateText.value = "点击进入";
	Object.assign(data, msg.data);
	
	return {
		loadingStateText,
		Enter
	}
}

export async function useCategory(cate) {
	let cateData = reactive({});
	if (!isLoaded.value) {
		await useServerData();
	}
	
	Object.assign(cateData, data[cate]);
	
	return {
		isLoaded,
		data: cateData,
		baseUrl
	}
}

export default useCategory;